//Fri Sep 16 16:33:59 CDT 2011
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class RGBStreet
{
	public int[][] RGB;
	
	public int[][] dp;
	
	public int estimateCost(String[] houses)
	{
		int N = houses.length;
		RGB = new int[N][3];
		dp = new int[N][3];	//R:0; G:1; B:2;
		
		for(int i=0; i<N; i++){
			String[] temp = houses[i].split(" ");
			for(int j=0; j<3; j++)
				RGB[i][j] = Integer.parseInt(temp[j]);
			
			dp[i][0] = Integer.MAX_VALUE;
			dp[i][1] = Integer.MAX_VALUE;
			dp[i][2] = Integer.MAX_VALUE;
		}
		
		dp[0][0] = RGB[0][0]; dp[0][1] = RGB[0][1]; dp[0][2] = RGB[0][2];
		
		for(int i=1; i<N; i++){
			for(int j=0; j<3; j++){
				for(int k=0; k<3; k++){
					if(j!=k){						
						dp[i][j] = Math.min(dp[i][j], dp[i-1][k] + RGB[i][j]);
					}
				}
			}
		}
		return Math.min(dp[N-1][0], Math.min(dp[N-1][1], dp[N-1][2]));
	}
	
	
}
//Powered by [KawigiEdit] 2.0!
